/**
 * @author Mie Plougstrup, Anders Abildgaard, Bo Stokholm 
 * @Version 16-12-2014
 */

package dbLayer;

import java.sql.ResultSet;
import java.sql.Statement;

public class DbMaxId {

	//Constructor
	public DbMaxId(){
	}
	
	public static int getMaxID(String columnName, String tableName){
		ResultSet results;
		int id = -1;
		String query = "SELECT MAX(" + columnName + ") FROM " + tableName;
		
		try{
			Statement stmt = DbConnection.getInstance().getDBcon().createStatement();
			stmt.setQueryTimeout(5);
			results = stmt.executeQuery(query);
			
			if(results.next())
				id = results.getInt(1);
			
		}catch(Exception e){
			System.out.println("Could get max: "+ e);//Delete after test
		}
		return id;
	}
}
